﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Enter.Entity;
using Enter.Common;
using Enter.BizLogic;
using Enter.Web.SystemAdmin;
namespace WebSystemAdmin.sys
{
    public partial class PopMenuListEdit : PageBase
    {
        public int ParentID = RequestStrHelper.GetIntFromRequest("ParentID", 0);
        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)
            {
                ListCtrlHelper.BindEnumOnListControl(ddl_IsValid, typeof(Sys_PopMenuListEntity.EnumIsValid));
                if (Request.QueryString["ID"] != null)
                {
                    GetInfo();
                }
                else
                {
                    this.ddl_IsValid.Items.FindByValue(((byte)Sys_PopMenuListEntity.EnumIsValid.Valid).ToString()).Selected = true;
                }
                txt_ParentNo.Text = ParentID.ToString();
            }
        }

        private void GetInfo()
        {
            Sys_PopMenuListBLLSub bll = new Sys_PopMenuListBLLSub();
            Sys_PopMenuListEntity model = bll.GetObjectByID(int.Parse(Request.QueryString["ID"]));
            if (model == null) return;
         
            txt_MenuNo.Text = model.MenuNo.ToString();
            txt_MenuText.Text = model.MenuText.ToString();
            txt_MenuUrl.Text = model.MenuUrl.ToString();
            txt_MenuOrder.Text = model.MenuOrder.ToString();
            txt_ParentNo.Text = model.ParentNo.ToString();
          
            this.ddl_IsValid.Items.FindByValue(((byte)model.IsValid).ToString()).Selected = true;
        }

        protected void btnApply_Click(object sender, EventArgs e)
        {
            Sys_PopMenuListEntity model = new Sys_PopMenuListEntity();
            Sys_PopMenuListBLLSub bll = new Sys_PopMenuListBLLSub();
            if (Request.QueryString["ID"] != null)
            {
                model.ID = int.Parse(Request.QueryString["ID"]);
            }
            model.MenuNo = txt_MenuNo.Text;
            model.MenuText = txt_MenuText.Text;
            model.MenuUrl = txt_MenuUrl.Text;
            model.MenuOrder = int.Parse(txt_MenuOrder.Text);
            model.ParentNo = txt_ParentNo.Text;
            model.UrlType = Sys_PopMenuListEntity.EnumUrlType.Url;
            model.IsValid = (Sys_PopMenuListEntity.EnumIsValid)byte.Parse(ddl_IsValid.SelectedItem.Value);
            if (bll.Save(model))
            {
                Utils.throwErrorGotoURL("操作成功", "PopMenuListList.aspx");
            }
            else
            {
                Utils.ShowMessage("操作失败");
            }
        }
    }
}
